#include "stdio.h"
#include "stdlib.h"

int *finalPrices(int *prices, int pricesSize, int *returnSize) {
    int *res = (int *) malloc(sizeof(int) * (pricesSize));
    *returnSize = pricesSize;
    for (int i = 0; i < pricesSize; ++i) {
        res[i] = prices[i];
        for (int j = i + 1; j < pricesSize; j++) {
            if (prices[j] <= res[i]) {
                res[i] -= prices[j];
                break;
            }
        }
    }
    return res;

}

int main() {

    int a[] = {8, 4, 6, 2, 3};

    int returnSize = 0;
    int *res = finalPrices(a, 5, &returnSize);

    for (int i = 0; i < returnSize; i++) {
        printf("%d ", res[i]);
    }
    free(res);

}